
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[EBAS_SP_SLET_STUDERENDE]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[EBAS_SP_SLET_STUDERENDE]
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE [DBO].[EBAS_SP_SLET_STUDERENDE] 
	@session varchar(255),
	@guid varchar(255)
WITH ENCRYPTION	
AS
	DECLARE
		@brugerGuid uniqueidentifier,
		@rettighed int

	SET NOCOUNT ON

	CREATE TABLE #temp ( rett int )
	INSERT INTO #temp (rett)
	EXEC EBAS.DBO.EBAS_SP_SIKKERHED_VERIFICER_SESSION @session	

	SET @rettighed = (SELECT IsNull(max(rett),0) FROM #temp)

	IF 8 <= @rettighed
	BEGIN
		DELETE FROM EBAS_FAG_STUDERENDE WHERE STUDERENDE_GUID = @guid	
		DELETE FROM EBAS_GRUPPE_STUDERENDE WHERE STUDERENDE_GUID = @guid	
		DELETE FROM DATO_NOTAT WHERE STUDERENDE_GUID = @guid

		SET @brugerGuid = (SELECT SIKKERHED_BRUGER_GUID FROM EBAS_STUDERENDE WHERE GUID = @guid)	

		DELETE FROM EBAS_SIKKERHED_RELATION WHERE SIKKERHED_BRUGER_GUID = @brugerGuid
		DELETE FROM EBAS_SIKKERHED_BRUGER WHERE GUID = @brugerGuid
	END
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
